<template>
    <div>
        <div class="toolbar">
            <el-form :inline="true"  class="demo-form-inline">
                <el-form-item>
                    <el-input v-model="searchShopName"  placeholder="店铺类别"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="$store.dispatch('getShopTypeList',{shopTypeName:searchShopName})">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button  type="success" @click="shopTypeVisible=true">添加店铺类别</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-dialog title="添加店铺类别" :visible.sync="shopTypeVisible">
            <el-form>
                <el-form-item label="店铺类别名称:" label-width="120px">
                    <el-input v-model="shopTypeForm.shopTypeName" autocomplete="off" style="width:200px"></el-input>
                </el-form-item>
                <el-form-item label="店铺类别图片:" label-width="120px">
                    <el-upload
                            name="shopTypePic"
                            :data="shopTypeForm"
                            ref="upload"
                            :headers="{
                              authorization:$store.state.admin.token
                            }"
                            :limit="1"
                            :auto-upload="false"
                            :on-success="success"
                            class="upload-demo"
                            action="/api/shopTypeList"
                            list-type="picture">
                        <el-button size="small" type="primary">点击上传</el-button>
                        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
                    </el-upload>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="shopTypeVisible=false">取 消</el-button>
                <el-button type="primary" @click="upShopType">提 交</el-button>
            </div>

        </el-dialog>
        <el-table
                v-loading="$store.state.load"
                :data="$store.state.shop.shopTypeList"
                style="width: 100%">
            <el-table-column
                    label="ID"
                    width="200">
                <template slot-scope="scope">
                    <span style="margin-left: 10px">{{ scope.row._id}}</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="上传时间"
                    width="200">
                <template slot-scope="scope">
                    <i class="el-icon-time"></i>
                    <span style="margin-left: 10px">{{ scope.row.createTime |date }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="修改时间"
                    width="200">
                <template slot-scope="scope">
                    <i class="el-icon-time"></i>
                    <span style="margin-left: 10px">{{ scope.row.upTime |date }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="店铺类别名称"
                    width="180">
                <template slot-scope="scope">
                    {{scope.row.shopTypeName}}
                </template>
            </el-table-column>
            <el-table-column
                    label="店铺类别图片"
                    width="180">
                <template slot-scope="scope">
                    <a :href="scope.row.shopTypePic | imgUrl" :title="scope.row.shopTypeName" target="_blank">
                        <img height="60px" :src="scope.row.shopTypePic |imgUrl" alt="">
                    </a>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            type="success"
                            @click="shopTypeId=scope.row._id;shopVisible=true">添加店铺</el-button>
                    <el-button
                            size="mini"
                            type="danger"
                            @click="$store.dispatch('deleteShop',scope.row._id)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <shop-dia-log v-if="shopVisible" :shopTypeId="shopTypeId" :shopVisible.sync="shopVisible"></shop-dia-log>

        <pageInfo action-name="getShopTypeList" :params="{shopTypeName:searchShopName}"></pageInfo>
    </div>
</template>

<script>
    import shopDiaLog from "@/components/DiaLogs/ShopDiaLog.vue"
    export default {

        name: "ShopTypeList",
        data(){
            return{
                shopTypeId:"",
                shopVisible:false,
                searchShopName:"",
                shopTypeForm:{
                    shopTypeName:''
                },
                shopTypeVisible:false
            }
        },
        components:{
            shopDiaLog
        },
        methods:{
            upShopType(){
                this.$refs.upload.submit()
                this.$store.dispatch("allShopTypeList")
            },
            success(data,file,fileList){
                if(data.ok==1){
                    this.shopTypeForm.shopTypeName=""
                    this.$refs.upload.clearFiles()
                    this.shopTypeVisible=false
                    this.$store.dispatch("getShopTypeList")
                    this.$message({
                        message:data.msg,
                        type: 'success',

                    });
                }else{
                    this.$message(data.msg);
                }
            }
        },
        mounted() {
            this.$store.dispatch("allShopTypeList")
        },


    }
</script>

<style scoped>

</style>